import { Actor, Action } from 'iflux2';
import { OrderListType } from '../constant/action-type';

export default class OrderList extends Actor {
    defaultState() {
        return {
            list: [],
            orderMapStatus: {},
            consigneeMap: {},
            initItemPriceMap: {},
            tradeOrderMap:{},
            loading: true,
            userLogos:{}
        }
    }


    @Action(OrderListType.SET_LIST)
    setList(state, { list, orderMapStatus, consigneeMap, initItemPriceMap,tradeOrderMap }) {
        return state.set('list', list)
            .set('orderMapStatus', orderMapStatus)
            .set('consigneeMap', consigneeMap)
            .set('initItemPriceMap', initItemPriceMap)
            .set('tradeOrderMap',tradeOrderMap);
    }

    @Action(OrderListType.SET_LOADING)
    setLoading(state, loading) {
        return state.set('loading', loading);
    }

    @Action(OrderListType.ORDER_REFUNDED)
    orderRefunded(state,rid){
        return state.update('list',(list)=>{
            return list.map(record=>{
                if(record.get("applyId") == rid){//将主商品添加activityId,组合数量加1
                    return record.set('status', 'REFUND');
                }
                return record;
            })
        })
    }

    @Action(OrderListType.SET_USER_LOGOS)
    setUserLogos(state,logos){
        return state.set('userLogos',logos)
    }
}